Skip to content

Keep SMB rename verification off the UI thread#4611

Open
venkyqz wants to merge 1 commit intoTeamAmaze:release/4.0from
venkyqz:fix-smb-rename-main-thread
Open

Keep SMB rename verification off the UI thread#4611
venkyqz wants to merge 1 commit intoTeamAmaze:release/4.0from
venkyqz:fix-smb-rename-main-thread

Conversation

@venkyqz
Copy link
Copy Markdown

@venkyqz venkyqz commented Apr 22, 2026

Problem:
The rename completion path in MainActivityHelper may call newFile.exists(context) on the UI thread after a rename attempt. For SMB targets that falls into HybridFile.exists() and performs synchronous SmbFile.exists() network I/O on the main thread.

Root cause:
The post-rename existence probe was added as a SAF workaround because DocumentFile.renameTo() can report false even when the rename succeeds, but the fallback was applied uniformly to all backends.

Fix:
Limit the post-rename exists(context) verification to SAF-backed targets (DOCUMENT_FILE and OTG) and skip that UI-thread probe for SMB and other non-SAF modes.

Closes #4610

Copilot AI review requested due to automatic review settings April 22, 2026 13:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents a potential UI-thread network call during rename completion by limiting the post-rename exists(context) verification to SAF-backed targets only (DocumentFile/OTG), avoiding SMB (and other non-SAF) synchronous checks on the main thread.

Changes:

  • Gate the post-rename newFile.exists(context) probe behind a SAF/OTG-only predicate in MainActivityHelper.
  • Add a small helper (shouldVerifyRenameWithExists) encapsulating the gating decision.
  • Add a focused unit test covering the SAF vs non-SAF decision behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java Skips UI-thread exists(context) verification for SMB/non-SAF rename completion; keeps it for SAF/OTG where the workaround is needed.
app/src/test/java/com/amaze/filemanager/utils/MainActivityHelperTest.java Adds regression coverage for the SAF/OTG-only verification decision.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/test/java/com/amaze/filemanager/utils/MainActivityHelperTest.java Outdated
Comment thread app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java Outdated
@venkyqz venkyqz force-pushed the fix-smb-rename-main-thread branch from 1bbd4da to a036ec2 Compare April 22, 2026 13:36
The rename completion path in MainActivityHelper re-checked success by calling newFile.exists(context) on the UI thread because SAF-backed renames can report false negatives. For SMB targets that fallback routes into HybridFile.exists() and performs synchronous network I/O on the main thread. Limit the fallback probe to SAF-backed targets and cover it with a focused regression test.

Constraint: Preserve the post-rename verification workaround for SAF-backed rename targets
Rejected: Change HybridFile.exists() semantics for all SMB callers | too broad and would affect background operations that legitimately rely on it
Confidence: high
Scope-risk: narrow
Directive: Keep rename completion fallbacks off the UI thread for remote backends; only use exists(context) as a SAF-specific verification path
Tested: ./gradlew :app:testFdroidDebugUnitTest --tests com.amaze.filemanager.utils.MainActivityHelperTest -x kaptFdroidDebugUnitTestKotlin
Tested: ./gradlew :app:compileFdroidDebugJavaWithJavac
Tested: ./gradlew :app:compileFdroidDebugUnitTestJavaWithJavac -x kaptFdroidDebugUnitTestKotlin
Not-tested: Full :app:testFdroidDebugUnitTest (blocked by existing kaptFdroidDebugUnitTestKotlin failure in unrelated tests referencing missing ShadowMultiDex)
@venkyqz venkyqz force-pushed the fix-smb-rename-main-thread branch from a036ec2 to 015f7cf Compare April 22, 2026 13:43
* instead of merely looking at the return value
*/
if (b || newFile.exists(context)) {
if (b
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix the issue (exists running on main thread) and seems incredibly easy to break if the implementation of Operations.rename changes (by changing how otg is handled or using DocumentFile for other file types). To fix the issue, the exists check should probably be moved to Operations.rename.

@EmmanuelMess EmmanuelMess added the PR-Requested-Changes this PR is awaiting an update from the author label Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Requested-Changes this PR is awaiting an update from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential ANR / NetworkOnMainThread Risk: Synchronous SMB network call in HybridFile.exists()

3 participants